import { is } from '@electron-toolkit/utils'
import { join, resolve } from 'path'
import fs from 'fs'
import {log} from './logManager'
import { Share } from './share'
import JSON5 from 'json5'

export const loadConfig = (): void => {
  let configPath: string
  if (is.dev) {
    configPath = resolve('config/config.json5')
  } else {
    const appPath = process.resourcesPath
    configPath = join(appPath, 'config', 'config.json5')
  }
  try {
    const strFile = fs.readFileSync(resolve(configPath), 'utf-8')
    const jsonConfig = JSON5.parse(strFile)
    Share.initConfig(jsonConfig)
    log.info('获取的配置信息为:', strFile)
  } catch (e) {
    log.warn(e)
  }
}
